﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightGolf.Client
{
    public partial class Fps : UserControl
    {
        List<double> previousFrames = new List<double>();
        public int averageOverValue = 100;

        public Fps()
        {
            InitializeComponent();
            Page.gameLoop.Update += GameLoop_Update;
        }

        private void GameLoop_Update(TimeSpan elapsedTime)
        {
            previousFrames.Add(elapsedTime.TotalSeconds);

            if (previousFrames.Count > averageOverValue)
            {
                previousFrames.RemoveAt(0);

                double totalFrameLength = 0;
                previousFrames.ForEach(f => totalFrameLength += f);


                this.FramesPerSecond.Text = (averageOverValue / totalFrameLength).ToString("00.000");
                this.FrameLength.Text = (totalFrameLength / averageOverValue).ToString(".00000");
            }
        }
    }
}
